import {
  qiankunWindow,
  renderWithQiankun,
} from 'vite-plugin-qiankun/dist/helper';
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';

let app;

// 判断是否在乾坤环境下，非乾坤环境按照正常逻辑渲染
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  createApp(App).use(router).mount('#app');
} else {
  renderWithQiankun({
    mount(props) {
      console.log('🚀 ~ mount ~ props:', props);
      console.log(props?.token, 'token');
      console.log(localStorage.getItem('cookie'), 'cookie111');
      const { container } = props;
      app = createApp(App);
      app.use(router);
      app.mount(container ? container.querySelector('#app') : '#app');
    },
    bootstrap() {
      console.log('子应用的 bootstrap');
    },
    unmount() {
      app.unmount();
    },
  });
}
